package com.teamone.mobilewatch;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class SplashActivity extends Activity {
	protected boolean _active = true;
	protected int _splashTime = 3000;
	Thread mSplashThread;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		// thread for displaying the SplashScreen
		// Thread splashTread = new Thread() {
		// @Override
		// public void run() {
		// try {
		// int waited = 0;
		// while(_active && (waited < _splashTime)) {
		// sleep(100);
		// if(_active) {
		// waited += 100;
		// }
		// }
		// } catch(InterruptedException e) {
		// // do nothing
		// } finally {
		// finish();
		// Log.d("Splash thread", "Launching next activity...");
		// Intent i = new Intent();
		// i.setClass(getApplicationContext(), LoginActivity.class);
		// startActivity(i);
		// }
		// }
		// };

		mSplashThread = new Thread() {
			@Override
			public void run() {
				try {
					synchronized (this) {
						// wait splash period of time or exit on touch
						wait(_splashTime);
					}
				} catch (InterruptedException e) {
					// do nothing
				} finally {
					finish();
					Log.d("Splash thread", "Launching next activity...");
					Intent i = new Intent();
					i.setClass(getApplicationContext(), LoginActivity.class);
					startActivity(i);
					stop();
				}
			}
		};

		mSplashThread.start();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {

		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			synchronized (mSplashThread) {
				mSplashThread.notifyAll();
			}
		}
		return true;
	}
}